package com.jgp.workflow.utils;

import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.TypeReference;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 项目   jgp-cloud-parent
 * 作者   loufei
 * 时间   2022/3/26
 */
public class ConvertBlobTypeHandler extends TypeReference<byte[]> implements TypeHandler<byte[]> {
	
	@Override
	public void setParameter(PreparedStatement ps, int i, byte[] parameter, JdbcType jdbcType) throws SQLException {
		ps.setBytes(i, parameter);
	}
	
	@Override
	public byte[] getResult(ResultSet rs, String columnName) throws SQLException {
		return rs.getBytes(columnName);
	}
	
	@Override
	public byte[] getResult(ResultSet rs, int columnIndex) throws SQLException {
		return rs.getBytes(columnIndex);
	}
	
	@Override
	public byte[] getResult(CallableStatement cs, int columnIndex) throws SQLException {
		return cs.getBytes(columnIndex);
	}
	
}
